package com.jt.controller;

import com.jt.pojo.User;
import com.jt.utils.ExcelUtil;
import io.netty.handler.codec.http.HttpResponse;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/excel")
public class ExcelController {
    @Value("${excel.path}")
    private  String path;
    @PostMapping("/export")
    public void exportExcel(HttpServletResponse response) {
        System.out.println("开始导出");
        List<User> userList=new ArrayList<>();
        User user=new User();
        user.setId("1123213123");
        user.setUsername("张三");
        user.setAge("18");
        user.setPassword("123456");
        User user1=new User();
        user1.setUsername("张三");
        user1.setAge("18");
        user1.setId("1123213123212");
        user1.setPassword("1234567");
        userList.add( user);
        userList.add( user1);
        String ResultPath=path+"\\"+"用户列表.xlsx";
        ExcelUtil.getExcel(userList, ResultPath,response);
    }
}
